package ar.edu.uba.fi.jmit.graphvisualizer.receiver;

import org.apache.log4j.Logger;

import ar.edu.uba.fi.jmit.graphvisualizer.server.ResourceProperties;
import ar.edu.uba.fi.jmit.graphvisualizer.server.storage.Registry;
import ar.edu.uba.fi.jmit.integrationcommons.Event;
import ar.edu.uba.fi.jmit.receiver.ReceiverObserver;

public class ReceiverObserverImpl implements ReceiverObserver {

	private final Logger logger = Logger.getLogger(this.getClass());

	private static ReceiverObserverImpl instance = new ReceiverObserverImpl();

	private ReceiverObserverImpl() {
		super();
	}

	public static ReceiverObserverImpl getInstance() {
		return instance;
	}

	@Override
	public void onRecivedEvent(Event event) {
		logger.debug("received event in graph visualizer");
		storeEventData(event);
	}

	private void storeEventData(Event event) {
		logger.debug("storeEventData of type " + event.getData().get(ResourceProperties.getProperty("jmit.graphvisualizer.type")));
		if(event.getData().get(ResourceProperties.getProperty("jmit.graphvisualizer.type")).equals("TYPE_RANGE")) {
			Registry.getAlertDataStorage().addData(event.getData());
		}else {
			Registry.getMonitoringDataStorage().addData(event.getData());
		}
	}

}
